'''
Created on 2011-10-16

@author: tony.li.fly@gmail.com
'''

from django.http import HttpResponse,HttpResponseRedirect
from django.shortcuts import render_to_response

from xyh.oa.models import User
import time

def login(request):
    
    count = User.objects.filter(name__exact = request.POST['name'],password = request.POST['password'],activable=True).count()
    if count == 0 :
        return HttpResponse("{success:false,data:{}}")
    else :
        request.session['user'] = User.objects.get(name=request.POST['name'])
        return HttpResponse("{success:true,data:{}}")

def header(request):
    user = request.session['user']
    
    return render_to_response('header.html',{'user':user,'time':time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())})
    
    
def logout(request):
    try:
        del request.session['user']
    except KeyError:
        pass
    return HttpResponseRedirect("/static/index.html")  
